<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="pg"  uri="http://jsptags.com/tags/navigation/pager" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="dwr/engine.js"></script>
<script type="text/javascript" src="dwr/util.js"></script>
<script type="text/javascript" src="dwr/interface/user.js"></script>
<title>用户${user.username }已拥有的角色</title>

	<SCRIPT type="text/javascript">
		function deleteLink(userid, linkid) {
			if(confirm("你真的要删除关联吗？")) {
				user.deleteUserRole(
    				userid,
    				linkid,
    				function(datas) {
    					var url = window.location.href;
						if(url.indexOf("&pager.offset") > 0) {//刷新页面，返回首页；如果不需要返回首页则不用对url处理
							url = url.substring(0,url.indexOf("&pager.offset"));
						}
						reload.href =  url + "&random="+Math.random(); 
						reload.click(); 
    				}
    			);
			}
		}
		
		function addRole() {
			window.showModalDialog("role-listSelect.action?user.id=${user.id}",null,"dialogWidth=580px;dialogHeight=400px");
			var url = window.location.href;
			if(url.indexOf("&pager.offset") > 0) {//刷新页面，返回首页；如果不需要返回首页则不用对url处理
				url = url.substring(0,url.indexOf("&pager.offset"));
			}
			reload.href =  url + "&random="+Math.random(); 
			reload.click(); 

			//alert("OK");//关闭弹出窗口时的回传参数
		}
		function addOrg() {
			window.showModalDialog("organization-list.action",null,"dialogWidth=510px;dialogHeight=300px");
			//alert(str);//关闭弹出窗口时的回传参数
		}
	</SCRIPT>
<base target="_self"/>
</head>
<body>

<a id="reload" href="" tyle="display:none"></a> 

<center>
<TABLE class="tableEdit" border="0" cellspacing="1" cellpadding="0" style="width:580px;">
	<TBODY>
		<TR>
			<!-- 这里是添加、编辑界面的标题 -->
			<td align="center" class="tdEditTitle">用户[${user.username }]已拥有的角色</TD>
		</TR>
		<TR>
			<td>
			<!-- 主输入域开始 -->
      <TABLE width="100%" border=0 align=center cellPadding=0 cellSpacing=0 borderColor=#ffffff style="FONT-SIZE: 10pt">
        <TBODY>
          <TR>
            <TD width="82%" height=14 align=right vAlign=center noWrap>
            </TD>
            <TD width="18%" align=right vAlign=center noWrap>　</TD>
          </TR>
          <TR>
            <TD height=14 align=right vAlign=center noWrap>
            	<!-- 在这里插入查询表单 -->
            </TD>
            <TD height=14 align="left" vAlign=center noWrap>
            <a href="javascript:addRole()">给用户分配角色</a>
            </TD>
          </TR>
          <TR>
            <TD height=28 colspan="2" align=right vAlign=center noWrap background=images/list_middle.jpg>&nbsp;&nbsp;
            <!-- 可以在这里插入分页导航条 -->
            </TD>
          </TR>
        </TBODY>
      </TABLE>
      <table width="100%" border="0" cellPadding="0" cellSpacing="1" bgcolor="#6386d6">
          <!-- 列表标题栏 -->
	      <tr bgcolor="#EFF3F7" class="TableBody1">
		      <td width="33%" height="37" align="center"><b>角色名称</b></td>
              <td width="34%" height="37" align="center"><b>操作</b></td>
          </tr>
          <!-- 列表数据栏 -->
          <c:if test="${!empty pm.resultList}">
			<c:forEach items="${pm.resultList}" var="info">
	      		<tr bgcolor="#EFF3F7" class="TableBody1" onmouseover="this.bgColor = '#DEE7FF';" onmouseout="this.bgColor='#EFF3F7';">
			      <td align="center" vAlign="center">${info.role.name }</td>
		          <td align="center" vAlign="center">
		          	<a href="javascript:deleteLink(${info.user.id },${info.role.id})">删除关联</a>
		          </td>
	            </tr>
        	</c:forEach>
        	
        	<TABLE width="100%" border=0 align=center cellPadding=0 cellSpacing=0 borderColor=#ffffff style="FONT-SIZE: 10pt">
        <TBODY>
          <TR>
            <TD height=28 align=right vAlign=center noWrap background=images/list_middle.jpg>&nbsp;&nbsp;
            <!-- 可以在这里插入分页导航条 -->
            <pg:pager url="user-listUserRole.action" maxPageItems="2" items="${pm.recordSum }" export="currentPageNumber=pageNumber">
				<pg:param name="user.id"/>
				<pg:first>
					<a href="${pageUrl}">首页</a>
				</pg:first>
				<pg:prev>
					<a href="${pageUrl}">前页</a>
				</pg:prev>
				<pg:pages>
					<c:choose>
						<c:when test="${currentPageNumber eq pageNumber}">
							<font color="red">${pageNumber }</font>
						</c:when>
						<c:otherwise>
							<a href="${pageUrl}">${pageNumber }</a>
						</c:otherwise>
					</c:choose>
				</pg:pages>
				<pg:next>
					<a href="${pageUrl}">下页</a>
				</pg:next>
				<pg:last>
					<a href="${pageUrl}">尾页</a>
				</pg:last>
			</pg:pager>
    		</TD>
          </TR>
        </TBODY>
      </TABLE>
        </c:if>
        <!-- 在列表数据为空的时候，要显示的提示信息 -->
        
	    <c:if test="${empty pm.resultList}">
	    <tr>
	    	<td colspan="7" align="center" bgcolor="#EFF3F7" class="TableBody1" onmouseover="this.bgColor = '#DEE7FF';" onmouseout="this.bgColor='#EFF3F7';">
	    	没有找到相应的记录
	    	</td>
	    </tr>
	    </c:if>
	    
      </table>
      
</center>

</body>

</html>
